      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ol class="breadcrumb">
            <li><a href="<?=site_url()?>/product/index">商品管理</a></li>
            <li class="active">商品列表</li>
          </ol>
          <div class="row margin-bottom-10">
            <div class="col-md-12">
              <ul class="nav nav-pills">
                <li class="active"><a href="<?=site_url()?>/product/add">添加商品</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/exportProductlist">导出商品</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/exportQuotation">导出报价单</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/exportPurprice">导出进货价</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/pricechange">查看价格变动</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/shelves">查看下架商品</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/shorts">查看补货中商品</a></li>
                 <li class="active"><a href="<?=site_url()?>/product/dividelist">拆分商品管理</a></li>
              </ul>          
            </div>
             </div> 
             <hr />
             <div class="row margin-bottom-5">
             <div class="col-md-12">
            	开始日期
            	<input type="text" id="startdate" name="startdate" value="2015-08-11">
            	结束日期
            	<input type="text" id="enddate" name="enddate" value="<?php echo date('Y-m-d',time()); ?>">
            	<button class="btn btn-primary" id="output_btn">导出库存</button>
            	<button class="btn btn-primary" id="check_btn">查看库存</button>
            	<button class="btn btn-primary" id="stock_btn">查看库存2</button>
            	<button class="btn btn-primary" id="product_btn">查看库存3</button>
            	<a class="btn btn-primary" href="<?=site_url()?>/stock/records">库存购买记录</a>
            </div>
            </div>
            <hr />
           <div class="row margin-bottom-5">
            <div class="col-md-12">
            		<input type="text" id="name" name="name" value="">
            		<select id="ordertype">
            			<option value="4" <?php if($ordertype ==4) echo "selected"; ?>>按上下架倒序排序</option>
            			<option value="3" <?php if($ordertype ==3) echo "selected"; ?>>按上下架正序排序</option>
            			<option value="1" <?php if($ordertype ==1) echo "selected"; ?>>按ID正序排序</option>
            			<option value="2" <?php if($ordertype ==2) echo "selected"; ?>>按ID倒序排序</option>
            		</select>
            		 <select id="category"  >
            		 	<option value="0">全部大类</option>
                   		<?php foreach ($categories as $category):?>
                    		<option value="<?php echo $category['id'];?>" <?php if($category['id'] ==$categoryid) echo "selected"; ?>><?php echo $category['name'];?></option>
                        <?php endforeach;?>
                      </select>  
                       <select id="variety" >
                       	<option value="0">全部小类</option>
                   		<?php foreach ($varieties as $variety):?>
                    		<option value="<?php echo $variety['id'];?>" <?php if($variety['id'] ==$varietyid) echo "selected"; ?>><?php echo $variety['name'];?></option>
                        <?php endforeach;?>
                      </select>  
                      <select id="sale">
                      	<option value="0" <?php if($sale==0) echo "selected"; ?>>普通商品</option>
            			<option value="1" <?php if($sale==1) echo "selected"; ?>>特价商品</option>
            		 </select>
            		  <select id="type">
                      	<option value="0" <?php if($type==0) echo "selected"; ?>>普通商品</option>
            			<option value="1" <?php if($type==1) echo "selected"; ?>>食堂商品</option>
            			<option value="2" <?php if($type==2) echo "selected"; ?>>特供商品</option>
            			<option value="2" <?php if($type==3) echo "selected"; ?>>乔司鱼府特供商品</option>
            		 </select>
            		 <select id="show">
                      	<option value="0" <?php if($show==0) echo "selected"; ?>>全部</option>
            			<option value="1" <?php if($show==1) echo "selected"; ?>>上架</option>
            			<option value="2" <?php if($show==2) echo "selected"; ?>>下架</option>
            		 </select>
            		  <select id="purprice">
                      	<option value="0" <?php if($purprice==0) echo "selected"; ?>>全部</option>
            			<option value="1" <?php if($purprice==1) echo "selected"; ?>>进货价为0</option>
            			<option value="2" <?php if($purprice==2) echo "selected"; ?>>进货价不为0</option>
            		 </select>
            		<button class="btn btn-primary" id="submit_btn">搜索</button>
            </div>
          </div> 
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                <h4 class="margin-bottom-15">商品列表</h4>
                <table class="table table-striped table-hover table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th width="15%">商品名称</th>
                      <th>大类</th>
                      <th>小类</th>
                      <th>进货价</th>
                      <th>出售价</th>
                      <th>起售数量</th>
                      <th>描述</th>
                      <th>排序号</th>
                      <th>导出号</th>
                      <th>上/下架</th>
                      <th>价格变化</th>
                      <th>操作</th>
                    </tr>
                  </thead>
                  <tbody>
                  	<?php foreach ($products as $item):?>
                    <tr>
                      <td><?php echo $item['id'];?></td>
                      <td><?php echo $item['name'];?></td>
                      <td><?php echo $item['category'];?></td>
                      <td>
                      <select class="variety" data-id="<?php echo $item['id'];?>" >
                   		<?php foreach ($varieties as $variety):?>
                    		<option value="<?php echo $variety['id'];?>" <?php if($variety['id'] == $item['varietyid']) echo "selected"; ?>><?php echo $variety['name'];?></option>
                        <?php endforeach;?>
                      </select>    
                      </td>
                      <td><input style="width:40px" type="text" id="pur<?php echo $item['id'];?>" value="<?php echo $item['purprice'];?>"><?php echo '元/'.$item['unit'];?>
                      	  <button class="purprice" data-id="<?php echo $item['id'];?>" >更新</button></td>
                      <td><input style="width:40px" type="text" id="pri<?php echo $item['id'];?>" value="<?php echo $item['price'];?>"><?php echo '元/'.$item['unit'];?>
                      	  <button class="price" data-id="<?php echo $item['id'];?>" >更新</button></td>
                      <td>
                      	  <input style="width:40px" type="text" id="start<?php echo $item['id'];?>" value="<?php echo $item['start'];?>">
                      	  <button class="start" data-id="<?php echo $item['id'];?>" >更新</button>
                      </td>
                      <td><?php echo $item['description'];?></td>
                      <td>
                      	  <input style="width:40px" type="text" id="num<?php echo $item['id'];?>" value="<?php echo $item['position'];?>">
                      	  <button class="position" data-id="<?php echo $item['id'];?>" >更新</button>
                      </td>
                      <td>
                      	  <input style="width:40px" type="text" id="ex<?php echo $item['id'];?>" value="<?php echo $item['export'];?>">
                      	  <button class="export" data-id="<?php echo $item['id'];?>" >更新</button>
                      </td>
                      <td>
                      	<?php 
                      		if($item['show']==1){
                     			echo '<a href="" class="btn btn-link hidepro" data-id="'.$item['id'].'" >下架</a>';
                      		}else{
                      			echo '<a href="" class="btn btn-link showpro" data-id="'.$item['id'].'" >上架</a>';
                      		}
                      	?>
                      </td>  
                       <td>
                     		<a href="<?php echo site_url('product/purpricechange/id/'.$item['id'])?>" >价格变化</a>
                      </td>  
                      <td>
                      		<a href="<?php echo site_url('product/edit/id/'.$item['id'])?>" class="btn btn-default">编辑</a>
                      		<!--
                      		<?php 
                      			if($item['discount']==0){
                      		?>
                      		<a href="" class="btn btn-link setdiscount" data-id="<?php echo $item['id'];?>" >设为特惠商品</a>
                      		 <?php 
                      		}else{
                      		?>
                      		<a href="" class="btn btn-link unsetdiscount" data-id="<?php echo $item['id'];?>" >取消特惠商品</a>
                      		  <?php
                      		}
                         	?>
                            -->                    
                    	 <a href="#" class="btn btn-link del" data-id="<?php echo $item['id'];?>" >删除</a>
                     </td>
                     
                    </tr>
                     <?php endforeach;?>
                  </tbody>
                </table>
              </div>
              <!--<ul class="pagination pull-right">
                <li class="disabled"><a href="#">&laquo;</a></li>
                <li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">2 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">3 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">4 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">5 <span class="sr-only">(current)</span></a></li>
                <li><a href="#">&raquo;</a></li>
              </ul>  -->
            </div>
          </div>
          <div class="pagination">
            <?php echo $links ;?>
          </div>
        </div>
      </div>
    <script>
	$(document).ready(function() {
		$('#startdate').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$('#enddate').datepicker({
			dateFormat: 'yy-mm-dd',
			monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
			dayNamesMin: ['日','一','二','三','四','五','六']
		});
		$("#output_btn").click(function() {
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			var url = "<?php echo site_url('product/exportStocks')?>";
			window.location.href=url+"/startdate/"+startdate+"/enddate/"+enddate;
		});
		$("#check_btn").click(function() {
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			var url = "<?php echo site_url('product/getStocks')?>";
			window.location.href=url+"/startdate/"+startdate+"/enddate/"+enddate;
		});
		$("#stock_btn").click(function() {
			var startdate = $("#startdate").val();
			var enddate = $("#enddate").val();
			var url = "<?php echo site_url('product/getNewStocks')?>";
			window.location.href=url+"/startdate/"+startdate+"/enddate/"+enddate;
		});
		$("#product_btn").click(function() {
			var url = "<?php echo site_url('product/getProductStocks')?>";
			window.location.href=url;
		});
		$("#submit_btn").click(function() {
			var name = $("#name").val();
			var ordertype = $("#ordertype").val();
			var category = $("#category").val();
			var variety = $("#variety").val();
			var sale = $("#sale").val();
			var purprice = $("#purprice").val();
			var type = $("#type").val();
			var show = $("#show").val();
			if(name==""||name==null){
				name="empty";
			}
			//name=encodeURIComponent(name);
			//alert(name);
			var url = "<?php echo site_url('product/index')?>";
			window.location.href=url+"/name/"+name+"/ordertype/"+ordertype+"/category/"+category+"/variety/"+variety+"/sale/"+sale+"/purprice/"+purprice+"/type/"+type+"/show/"+show;
		});
		$("#name").keydown(function(e) {
			if(e.keyCode == 13) {
				var name = $("#name").val();
				var ordertype = $("#ordertype").val();
				var category = $("#category").val();
				var variety = $("#variety").val();
				var sale = $("#sale").val();
				var purprice = $("#purprice").val();
				var type = $("#type").val();
				var show = $("#show").val();
				if(name==""||name==null){
					name="empty";
				}
				var url = "<?php echo site_url('product/index')?>";
				window.location.href=url+"/name/"+name+"/ordertype/"+ordertype+"/category/"+category+"/variety/"+variety+"/sale/"+sale+"/purprice/"+purprice+"/type/"+type+"/show/"+show;
			}
		});
		$(".del").click(function() {
			if(confirm("确定要删除该数据吗？"))
			{
			var id = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/delete')?>',
				type : "post",
				async : false,
				data : {
					'id' : id
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
			}
		});
		$(".hidepro").click(function() {
			if(confirm("确定要下架吗？"))
			{
			var productid= $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductstate')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'state':0
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
			}
		});
		$(".showpro").click(function() {
			if(confirm("确定要上架吗？"))
			{
			var productid = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductstate')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'state':1
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
			}
		});
		$(".variety").change(function () {
            //change事件
            var varietyid = $(this).val();
            var id = $(this).attr("data-id");
            //alert(id);
            //alert(varietyid);
			$.ajax({
				url : '<?php echo site_url('product/update')?>',
				type : "post",
				async : false,
				data : {
					'id':id,
					'varietyid' : varietyid
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
         });
         
		$(".purprice").click(function() {
			var productid = $(this).attr("data-id");
			var purprice = $("#pur"+productid).val();
			$.ajax({
				url : '<?php echo site_url('product/setproductpurprice')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'purprice':purprice
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
		});
		
		$(".price").click(function() {
			var productid = $(this).attr("data-id");
			var price = $("#pri"+productid).val();
			$.ajax({
				url : '<?php echo site_url('product/setproductprice')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'price':price
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
		});
		
		$(".start").click(function() {
			var productid = $(this).attr("data-id");
			var start = $("#start"+productid).val();
			$.ajax({
				url : '<?php echo site_url('product/setproductstart')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'start':start
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
		});
		
		$(".position").click(function() {
			var productid = $(this).attr("data-id");
			var position = $("#num"+productid).val();
			$.ajax({
				url : '<?php echo site_url('product/setproductposition')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'position':position
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
		});
		
		$(".export").click(function() {
			var productid = $(this).attr("data-id");
			var exportid = $("#ex"+productid).val();
			$.ajax({
				url : '<?php echo site_url('product/setproductexport')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'export':exportid
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
					
				}
			});
		});
		
			$(".setdiscount").click(function() {
				if(confirm("确定要设为特惠商品吗？"))
			{
			var productid = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductdiscount')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'discount' : 1
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		
		$(".unsetdiscount").click(function() {
				if(confirm("确定要取消特惠商品吗？"))
			{
			var productid = $(this).attr("data-id");
			$.ajax({
				url : '<?php echo site_url('product/setproductdiscount')?>',
				type : "post",
				async : false,
				data : {
					'productid' : productid,
					'discount' : 0
				},
				dataType : "json",
				timeout : "1000",
				error : function() {
					alert("服务加载出错");
				},
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
			}
		});
		
	}); 
</script>